#include"LinkQueue.h"
#include"LinkStack.h"
#include<stdio.h>
#define true 1
#define false 0

struct QueueStack
{
    LQueue queue1;
    LQueue queue2;
};

int InitQueueStack(struct QueueStack *s)
{
    InitLQueue(&s->queue1);
    InitLQueue(&s->queue2);
    return true;
}

void QueueStackPush(struct QueueStack *s,ElementType element)
{
    if(s->queue1.queue.len==0)
    {
        QPush(&s->queue2,element);
    }
    else
    {
        QPush(&s->queue1,element);
    }
}

int IsQueueStackEmpty(struct QueueStack *s)
{
    if(s->queue1.queue.len==0 && s->queue2.queue.len==0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

ElementType *QueueStackPop(struct QueueStack *s)
{
    if(IsQueueStackEmpty(s)==true)
    {
        printf("stack is empty!\n");
        return NULL;
    }
    if(s->queue1.queue.len==0)
    {
        while(s->queue2.queue.len>1)
        {
            QPush(&s->queue1,*QPop(&s->queue2));
        }
        return QPop(&s->queue2);
    }
    else
    {
        while(s->queue1.queue.len>1)
        {
            QPush(&s->queue2,*QPop(&s->queue1));
        }
        return QPop(&s->queue1);        
    }
}

int main()
{
    struct QueueStack s;
    InitQueueStack(&s);
    for(int i=0;i<10;i++)
    {
        QueueStackPush(&s,i+1);
    }
    while(IsQueueStackEmpty(&s)==false)
    {
        printf("%d ",*QueueStackPop(&s));
    }
    printf("\n");
    return 0;
}